package demo1;

public class Test1 {
    public static void main(String[] args) {
       String a = "bb aa " ;
       String b = trans(a,a.length()) ;
        System.out.println(b.length());
        System.out.println(b);
    }
    public static String trans (String s, int n) {
        // write code here
        StringBuffer str = new StringBuffer() ;
        for(int i = 0 ; i < n ; i++){
            char ch = s.charAt(i) ;
            if(ch >= 'a' && ch <= 'z'){
                str.append((char)(ch -('a' - 'A'))) ;
            }else if(ch >= 'A' && ch <= 'Z'){
                str.append((char)(ch + ('a' - 'A'))) ;
            }else{
                str.append(" ") ;
            }
        }
        str.reverse() ;
        for(int i = 0 ; i < n ; i ++ ){
            int j = i ;
            while(j < n && str.charAt(j)!=' '){
                j ++;
            }
            StringBuffer str2 = new StringBuffer(str.substring(i , j)) ;
            str2.reverse() ;
            str.replace(i , j , str2.toString()) ;
            i = j ;

        }
        return str.toString() ;
    }
}
